function searchInsert(nums, target) {
    var length = nums.length - 1, r = length, l = 0;
    while (r >= l) {
        var mid = (l + r) >> 1;
        if (nums[mid] === target) {
            return mid;
        }
        else if (nums[mid] > target) {
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    return r + 1;
}
;
console.log(searchInsert([1, 3, 5, 6], 7));
